<? 
session_start();
if(!session_is_registered(uid)){
    echo "You have to login to view this page!</br></br>";
    echo "Click here to return to the "; 
    echo '<a href="./../index.php" title="Login">Login Page</a></br></br>';
    echo "Or sign up using this link ";
    echo '<a href="./../Registration/registration.html" title="Registration">Registration Page</a>';
exit();
}
else

    //Manual SQL Connection
    $con = mysql_connect("localhost", "root", "root") or die ( "Error connectiong to DB: ".mysql_error());
       
    mysql_select_db("reeferslog", $con) or die ( "Error selecting specific DB, reefeerslog: ".mysql_error());

if ($_GET['action'] == 'edit') {
    
    $qry = "SELECT * from reactors where user_id='".$_SESSION['uid']."' and id='".$_GET['id']."'";
    
    $results = mysql_query($qry)or die(mysql_error($con));

    extract(mysql_fetch_assoc($results));
    
}else {
    //set values blank
    
    //Date variables
    $day = 0;
    $month = 0;
    $year = 0;
    
    $day1 = 0;
    $month1 = 0;
    $year1 = 0;
    
    //Function to make a valid date input
    $date_installed = $year."-".$month."-".$day;
    $media_changed = $year1."-".$month1."-".$day1; 
    
    //Extrapolate the date
    list($year, $month, $day) = explode("-", $date_installed);
    list($year, $month, $day) = explode("-", $media_changed);
    
    
    //reactor variables
    $media = '';
    $reactortype = '';
    $manufacturer = '';  
    
}

?>

<html>
<head>
    <link rel="stylesheet" type="text/css" href="http://localhost/ReefersLogApp/CSS/Generalpagelayout.css" />
    
    <script type='text/javascript' src='http://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.min.js'></script>
    <script type='text/javascript' src='./../scripts/js/jquery.ba-hashchange.min.js'></script>
    <script type='text/javascript' src='./../scripts/js/dynamicpage.js'></script>
    <title><?php echo ucfirst($_GET['action']); ?>Equip</title>
</head>
<div id="container">
	<div id="header">
            <h1>
		Reefers Log
            </h1>
	</div>
	<div id="navigation">
		<ul>
			<li><a href="./../WelcomePage/WelcomePage.php">Home</a></li>
			<li><a href="./../Profile/userprofile.php">Profile</a></li>
			<li><a href="./../Tools/tools.php">Tools</a></li>
			<li><a href="./../Logout/logout.php">Logout</a></li>
		</ul>
	</div>
	<div id="content-container">
		<div id="section-navigation">
                    <object id="loader" name="frameloader" type="text/html" data="http://localhost/ReefersLogApp/Welcome/WelcomePage.php/"></object>
			<ul>
                                <!--<li><a href="viewequip.php">View All Equipment</a></li>-->
				<li><a href="pumps.php">View Pumps</a></li>
				<li><a href="viewskimmer.php">View Skimmer</a></li>				
                                <li><a href="reactors.php">View Reactors</a></li>
                                <li><a href="./../Lighting/Lighting.html">Lights</a></li>
				
			</ul>
		</div>
		<div id="content">
                    <h2>
                        Your Aquarium Statistics:
                    </h2>
                    <p>
                        Edit your equipment logging regarding your aquarium. You may complete the form below or select another option
                        from the menu on the left to track your equipment.
                    </p>
		</div>
            <div id="content">
                    <h2>
                        Update the form below:
                    </h2>

<div align="center">  
                        <form action="commitedit.php?action=<?php echo $_GET['action'] ?>&type=reactors&id=<?php echo $_GET['id']?>" method="post">
                            <table border="1">
                                <thead>
                                <th>Reactors:</th>
                                <th>Manufacturer:<input type="text" name="manufacturer" value="<? echo $manufacturer ?>" /></th>
                                </thead>
                                <tbody>
                                    <tr>
                                    <td>Reactor Type:<select name="reactortype">
                                            <option value="" SELECTED></option>
                                        <?php 
                                            $t = mysql_query("select id, reactortype from reactors where user_id='".$_SESSION['uid']."' and id='".$_GET['id']."' order by reactortype");
                                            while($row = mysql_fetch_array($t)){
                                               $selected = " SELECTED";
                                               if ( $row['reactortype'] == $reactortype){
                                                           $selected = " SELECTED";
                                                        } else {
                                                           $selected = "";
                                                        }
                                                        echo '<OPTION value="'.$row['id'].'"'.$selected.'>'.$row['reactortype'].'</OPTION>'."\r\n";
                                                     }
                                            ?>
                                            <option>Bio-Pellet</option>
                                            <option>Calcium</option>
                                            <option>Carbon</option>
                                            <option>Kalk</option>
                                            <option>Ozone</option>
                                            <option>Phosphate</option>
                                            <option>Sulfur</option>
                                            <option>Zeo</option>
                                        </select>
                                    </td>
                                    <td>Media:<input type="text" name="media" value="<? echo $media?>" /></td>
                                    </tr>
                                    <tr>
                                    <td>Media Added Date:</br><select name="month2">
                                            <option value="" SELECTED>
                                            <?php 
                                            $month = mysql_query("select id, date_installed from reactors where user_id='".$_SESSION['uid']."' and id='".$_GET['id']."' order by date_installed desc");
                                            while($row = mysql_fetch_array($month)){
                                               $selected = " SELECTED";
                                               if ( $row['date_installed'] == $date_installed){
                                                           $selected = " SELECTED";
                                                           list($year, $month, $day) = explode("-", $date_installed);
                                                        } else {
                                                           $selected = "";
                                                        }
                                                        echo '<OPTION value="'.$row['id'].'"'.$selected.'>'.$month.'</OPTION>'."\r\n";                                                                                                                                                                                 
                                            }
                                            ?>
                                        <option>01</option>
                                        <option>02</option>
                                        <option>03</option>
                                        <option>04</option>
                                        <option>05</option>
                                        <option>06</option>
                                        <option>07</option>
                                        <option>08</option>
                                        <option>09</option>
                                        <option>10</option>
                                        <option>11</option>
                                        <option>12</option>
                                    </select><select name="day2">
                                        <option value="" SELECTED>
                                            <?php 
                                            $d = mysql_query("select id, date_installed from reactors where user_id='".$_SESSION['uid']."' and id='".$_GET['id']."' order by date_installed desc");
                                            while($row = mysql_fetch_array($d)){
                                               $selected = " SELECTED";
                                               if ( $row['date_installed'] == $date_installed){
                                                           $selected = " SELECTED";
                                                           list($year, $month, $day) = explode("-", $date_installed);
                                                        } else {
                                                           $selected = "";
                                                        }
                                                        echo '<OPTION value="'.$row['id'].'"'.$selected.'>'.$day.'</OPTION>'."\r\n";                                                                                                                                                                                 
                                            }
                                            ?>
                                        <option>01</option>
                                        <option>02</option>
                                        <option>03</option>
                                        <option>04</option>
                                        <option>05</option>
                                        <option>06</option>
                                        <option>07</option>
                                        <option>08</option>
                                        <option>09</option>
                                        <option>10</option>
                                        <option>11</option>
                                        <option>12</option>
                                        <option>13</option>
                                        <option>14</option>
                                        <option>15</option>
                                        <option>16</option>
                                        <option>17</option>
                                        <option>18</option>
                                        <option>19</option>
                                        <option>20</option>
                                        <option>21</option>
                                        <option>22</option>
                                        <option>23</option>
                                        <option>24</option>
                                        <option>25</option>
                                        <option>26</option>
                                        <option>27</option>
                                        <option>28</option>
                                        <option>29</option>
                                        <option>30</option>
                                        <option>31</option>
                                    </select><select name="year2">
                                        <option value="" SELECTED>
                                            <?php 
                                            $y = mysql_query("select id, date_installed from reactors where user_id='".$_SESSION['uid']."' and id='".$_GET['id']."' order by date_installed desc");
                                            while($row = mysql_fetch_array($y)){
                                               $selected = " SELECTED";
                                               if ( $row['date_installed'] == $date_installed){
                                                           $selected = " SELECTED";
                                                           list($year, $month, $day) = explode("-", $date_installed);
                                                        } else {
                                                           $selected = "";
                                                        }
                                                        echo '<OPTION value="'.$row['id'].'"'.$selected.'>'.$year.'</OPTION>'."\r\n";                                                                                                                                                                                 
                                            }
                                            ?>
                                        <option>2012</option>
                                        <option>2013</option>
                                        <option>2014</option>
                                        <option>2015</option>
                                        <option>2016</option>
                                        <option>2017</option>
                                        <option>2018</option>
                                        <option>2019</option>
                                        <option>2020</option>
                                        <option>2021</option>
                                        <option>2022</option>
                                        <option>2023</option>
                                        <option>2024</option>
                                        <option>2025</option>
                                        <option>2026</option>
                                        <option>2027</option>
                                        <option>2028</option>
                                        <option>2029</option>
                                        <option>2030</option>
                                    </td>
                                    <td>Media Change Date:</br><select name="month3">
                                            <option value="" SELECTED>
                                            <?php 
                                            $month = mysql_query("select id, media_changed from reactors where user_id='".$_SESSION['uid']."' and id='".$_GET['id']."' order by media_changed desc");
                                            while($row = mysql_fetch_array($month)){
                                               $selected = " SELECTED";
                                               if ( $row['media_changed'] == $media_changed){
                                                           $selected = " SELECTED";
                                                           list($year1, $month1, $day1) = explode("-", $media_changed);
                                                        } else {
                                                           $selected = "";
                                                        }
                                                        echo '<OPTION value="'.$row['id'].'"'.$selected.'>'.$month1.'</OPTION>'."\r\n";                                                                                                                                                                                 
                                            }
                                            ?>
                                        <option>01</option>
                                        <option>02</option>
                                        <option>03</option>
                                        <option>04</option>
                                        <option>05</option>
                                        <option>06</option>
                                        <option>07</option>
                                        <option>08</option>
                                        <option>09</option>
                                        <option>10</option>
                                        <option>11</option>
                                        <option>12</option>
                                    </select><select name="day3">
                                        <option value="" SELECTED>
                                            <?php 
                                            $d = mysql_query("select id, media_changed from reactors where user_id='".$_SESSION['uid']."' and id='".$_GET['id']."' order by media_changed desc");
                                            while($row = mysql_fetch_array($d)){
                                               $selected = " SELECTED";
                                               if ( $row['media_changed'] == $media_changed){
                                                           $selected = " SELECTED";
                                                           list($year1, $month1, $day1) = explode("-", $media_changed);
                                                        } else {
                                                           $selected = "";
                                                        }
                                                        echo '<OPTION value="'.$row['id'].'"'.$selected.'>'.$day1.'</OPTION>'."\r\n";                                                                                                                                                                                 
                                            }
                                            ?>
                                        <option>01</option>
                                        <option>02</option>
                                        <option>03</option>
                                        <option>04</option>
                                        <option>05</option>
                                        <option>06</option>
                                        <option>07</option>
                                        <option>08</option>
                                        <option>09</option>
                                        <option>10</option>
                                        <option>11</option>
                                        <option>12</option>
                                        <option>13</option>
                                        <option>14</option>
                                        <option>15</option>
                                        <option>16</option>
                                        <option>17</option>
                                        <option>18</option>
                                        <option>19</option>
                                        <option>20</option>
                                        <option>21</option>
                                        <option>22</option>
                                        <option>23</option>
                                        <option>24</option>
                                        <option>25</option>
                                        <option>26</option>
                                        <option>27</option>
                                        <option>28</option>
                                        <option>29</option>
                                        <option>30</option>
                                        <option>31</option>
                                    </select><select name="year3">
                                        <option value="" SELECTED>
                                            <?php 
                                            $y = mysql_query("select id, media_changed from reactors where user_id='".$_SESSION['uid']."' and id='".$_GET['id']."' order by media_changed desc");
                                            while($row = mysql_fetch_array($y)){
                                               $selected = " SELECTED";
                                               if ( $row['media_changed'] == $media_changed){
                                                           $selected = " SELECTED";
                                                           list($year1, $month1, $day1) = explode("-", $media_changed);
                                                        } else {
                                                           $selected = "";
                                                        }
                                                        echo '<OPTION value="'.$row['id'].'"'.$selected.'>'.$year1.'</OPTION>'."\r\n";                                                                                                                                                                                 
                                            }
                                            ?>
                                        <option>2012</option>
                                        <option>2013</option>
                                        <option>2014</option>
                                        <option>2015</option>
                                        <option>2016</option>
                                        <option>2017</option>
                                        <option>2018</option>
                                        <option>2019</option>
                                        <option>2020</option>
                                        <option>2021</option>
                                        <option>2022</option>
                                        <option>2023</option>
                                        <option>2024</option>
                                        <option>2025</option>
                                        <option>2026</option>
                                        <option>2027</option>
                                        <option>2028</option>
                                        <option>2029</option>
                                        <option>2030</option>
                                    </td>                                
                                </tr>
 
</tbody>
</table>
        <input align="center" type="submit" value="Update Reactors"/>
</div>
</form>
</div>
		<div id="aside">
                    <h3>
                        Info:
                    </h3>
                    <p>
                     You can edit your equipment options from the left.
                    </p>
		</div>
		<div id="footer">
			Copyright © ReefersLog, 2012, wkoester All Rights Reserved
		</div>
	</div>
</div>
</html>